package com.ruoyi.web.controller.finance;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.finance.domain.FmsShop;
import com.ruoyi.finance.service.IFmsShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 店铺 操作处理
 *
 * @author 夜雨
 */
@RestController
@RequestMapping("/finance/shop")
public class FmsShopController extends BaseController
{
    @Autowired
    private IFmsShopService shopService;

    /**
     * 获取店铺列表
     */
    @PreAuthorize("@ss.hasPermi('finance:shop:list')")
    @GetMapping("/list")
    public TableDataInfo list(FmsShop shop)
    {
        startPage();
        List<FmsShop> list = shopService.selectShopList(shop);
        return getDataTable(list);
    }

    /**
     * 根据店铺编号获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('finance:shop:query')")
    @GetMapping(value = "/{shopId}")
    public AjaxResult getInfo(@PathVariable Long shopId)
    {
        return success(shopService.selectShopById(shopId));
    }

    /**
     * 新增店铺
     */
    @PreAuthorize("@ss.hasPermi('finance:shop:add')")
    @Log(title = "店铺", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody FmsShop shop)
    {
        shop.setCreateBy(getUsername());
        return toAjax(shopService.insertShop(shop));
    }

    /**
     * 修改店铺
     */
    @PreAuthorize("@ss.hasPermi('finance:shop:edit')")
    @Log(title = "店铺", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody FmsShop shop)
    {
        shop.setUpdateBy(getUsername());
        return toAjax(shopService.updateShop(shop));
    }

    /**
     * 删除店铺
     */
    @PreAuthorize("@ss.hasPermi('finance:shop:remove')")
    @Log(title = "店铺", businessType = BusinessType.DELETE)
    @DeleteMapping("/{shopIds}")
    public AjaxResult remove(@PathVariable Long[] shopIds)
    {
        return toAjax(shopService.deleteShopByIds(shopIds));
    }
}
